package com.example.kt_base.s6

//TODO 107.Kotlin语言的泛型类型约束
open class MyAnyClass(name:String)
open class PersonClass(name:String):MyAnyClass(name)
class StudentClass(name: String):PersonClass(name)
class TeacherClas(name:String):PersonClass(name)
class DogClass(name: String)

//T:PersonClass 相当于java的 T extends PersonClass
class KtBase107<T:PersonClass>(val inputTypeValue:T,private val isR:Boolean=true){
    fun getObj()=inputTypeValue.takeIf { isR }
}
fun main() {
    val any=MyAnyClass("jenny")
    val per=PersonClass("jenny1")
    val stu=StudentClass("jenny2")

    //不能用
    /*val r1=KtBase107(any).getObj()
    println(r1)*/

    val r2=KtBase107(per).getObj()
    println(r2)

    val r3=KtBase107(stu).getObj()
    println(r3)

}
